home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Disk / Directory / savetext.c < prev    next >
Encoding:
Text File  |  1993-02-03  |  1.9 KB  |  100 lines  |  [TEXT/KAHL]

  1. //-- SaveText.c
  2.  
  3. // This writes out a text file containing the information that was contained in
  4. // the directory listing, albeit not in as nice a manner, maybe....
  5.  
  6. #include <stdio.h>
  7. #include "struct.h"
  8.  
  9.  
  10.  
  11. //--SaveText
  12.  
  13. // Write the top window as text.
  14.  
  15. SaveText()
  16. {
  17.     struct DrawWindow *w;
  18.     Point p;
  19.     SFReply reply;
  20.     char buffer[255];
  21.     short refnum;
  22.     long len;
  23.     long x;
  24.     short y;
  25.     short llen;
  26.     struct DirectData *ptr;
  27.     long l;
  28.     CursHandle cursor;
  29.  
  30.     w = ((struct DrawWindow *)FrontWindow());
  31.     if (w == NULL) return;
  32.     if (w->w.windowKind != WK_PLAN) return;
  33.  
  34.     p.h = p.v = 75;
  35.     strcpy(buffer,w->vName);
  36.     strcat(buffer,".DIR");
  37.     CtoPstr(buffer);
  38.     SFPutFile(p,"\pSave directory as:",buffer,NULL,&reply);
  39.     if (!reply.good) return;
  40.  
  41.     cursor = GetCursor(watchCursor);
  42.     HLock(cursor);
  43.     SetCursor(*cursor);
  44.     HUnlock(cursor);
  45.     HPurge(cursor);
  46.  
  47.     Create(reply.fName,reply.vRefNum,'EDIT','TEXT');
  48.     if (FSOpen(reply.fName,reply.vRefNum,&refnum)) return;
  49.     len = GetHandleSize(w->data) / sizeof(struct DirectData);
  50.     HLock(w->data);
  51.     ptr = *(w->data);
  52.     for (x = 0; x < len; x++) {
  53.         llen = 0;
  54.         for (y = 0; y < ptr[x].indent; y++) {
  55.             l = 2;
  56.             FSWrite(refnum,&l,"| ");
  57.             llen += 2;                        /* Tabs are 4 spaces */
  58.         }
  59.         llen++;
  60.         l = 1;
  61.         FSWrite(refnum,&l," ");
  62.         
  63.         PtoCstr(ptr[x].data);
  64.         l = strlen(ptr[x].data);
  65.         llen += l;
  66.         FSWrite(refnum,&l,ptr[x].data);
  67.         CtoPstr(ptr[x].data);
  68.         
  69.         if (ptr[x].auxdata[0] != '\0') {
  70.             while (llen < 60) {
  71.                 llen += 4 - llen % 4;
  72.                 l = 1;
  73.                 FSWrite(refnum,&l,"\t");
  74.             }
  75.             
  76.             PtoCstr(ptr[x].auxdata);
  77.             l = strlen(ptr[x].auxdata);
  78.             llen += l;
  79.             FSWrite(refnum,&l,ptr[x].auxdata);
  80.             CtoPstr(ptr[x].auxdata);
  81.             while (llen < 72) {
  82.                 llen += 4 - llen % 4;
  83.                 l = 1;
  84.                 FSWrite(refnum,&l,"\t");
  85.             }
  86.             
  87.             PtoCstr(ptr[x].auxdata2);
  88.             l = strlen(ptr[x].auxdata2);
  89.             llen += l;
  90.             FSWrite(refnum,&l,ptr[x].auxdata2);
  91.             CtoPstr(ptr[x].auxdata2);
  92.         }
  93.         l = 1;
  94.         FSWrite(refnum,&l,"\r");
  95.     }
  96.     HUnlock(w->data);
  97.     FSClose(refnum);
  98.     InitCursor();
  99. }
  100.